package com.lijin.converters;

import com.lijin.dataobject.dto.UserDto;
import com.lijin.dataobject.entity.User;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by gold-jx on 2017/6/3.
 */
public class UserConverter implements EntityToDtoConverter<User,UserDto>{


    @Override
    public UserDto convert(User source) {
        if (source == null) {
            return null;
        }
        UserDto userDto=new UserDto();
        userDto.setTbName(source.getTbName());
        userDto.setTbSex(source.getTbSex());
        userDto.setTbAge(source.getTbAge());
        return userDto;
    }

    @Override
    public List<UserDto> converters(List<User> list) {
        List<UserDto> userDtoList=new ArrayList<>();

        for (User user:list){
            UserDto userDto=new UserDto();
            userDto.setTbName(user.getTbName());
            userDto.setTbSex(user.getTbSex());
            userDto.setTbAge(user.getTbAge());
            userDto.setId(user.getId());
            userDto.setCreateTime(user.getCreateTime());
            userDtoList.add(userDto);
        }

        return userDtoList;
    }
}
